package com.mingtu.jgspatrol.adapter;

import android.content.Context;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.StringUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mingtu.jgspatrol.R;
import com.mingtu.jgspatrol.bean.TaskTemBean;

public class Task2Adapter extends BaseQuickAdapter<TaskTemBean.PageBean.ListBean, BaseViewHolder> {
    private  Context context;
    public Task2Adapter(Context context) {
        super(R.layout.item_task);
        this.context = context;
    }

    protected void convert(@NonNull BaseViewHolder helper, TaskTemBean.PageBean.ListBean listBean) {
        String taskName = listBean.getName();
        String beginTime = listBean.getCreateTime();
        String endTime = listBean.getFinishTime();
        int status = listBean.getStatus();
        String isFinish = listBean.getIsFinish();


        if (!StringUtils.isEmpty(taskName)) {
            helper.setText(R.id.tv_task_name, taskName);
        }

        if (!StringUtils.isEmpty(beginTime)) {
            helper.setText(R.id.tv_create_time, "开始时间：" + beginTime);
        }

        if (!StringUtils.isEmpty(endTime)) {
            helper.setText(R.id.tv_end_time, "截止时间：" + endTime);
        }

        helper.setText(R.id.tv_task_type, "任务类型：其他任务");

        if (isFinish.equals("0")) {
            helper.setGone(R.id.layout_status, true);
            helper.setGone(R.id.tv_complete_rate, false);
            helper.setTextColor(R.id.tv_task_name, context.getResources().getColor(R.color.text_color333));

            setTextColor(helper, context.getResources().getColor(R.color.text_color666));
        } else if (isFinish.equals("1")) {

            helper.setGone(R.id.layout_status, false);

            helper.setTextColor(R.id.tv_task_name, context.getResources().getColor(R.color.text_color999));

            helper.setGone(R.id.tv_complete_rate, true);
            helper.setText(R.id.tv_complete_rate, "已完成");
            helper.setTextColor(R.id.tv_complete_rate, context.getResources().getColor(R.color.text_color999));


            setTextColor(helper, context.getResources().getColor(R.color.text_color999));
        }
    }

    /**
     * 设置字体颜色
     *
     * @param color
     */
    private void setTextColor(BaseViewHolder helper, int color) {
        helper.setTextColor(R.id.tv_task_name, color);
        helper.setTextColor(R.id.tv_create_time, color);
        helper.setTextColor(R.id.tv_end_time, color);
    }



}
